//
//  WBNavigationController.swift
//  simpleWeibo


import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的navigationBar
        navigationBar.isHidden = true
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //隐藏底部的tabBar
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = viewController as? WBBaseController {
                var title = "返回"
                
                //判断控制器的级数, 只有一个子控制器的时候, 显示栈低控制器的标题
                if children.count == 1 {
                    title = children.first?.title ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToBack), isBack: true)
                
            }
        }
        
        super.pushViewController(viewController, animated: true)
    }
    
    @objc fileprivate func popToBack() {
        self.popViewController(animated: true)
        
    }
}
